package com.sfh.base.util;

import com.google.gson.Gson;
import com.jfinal.json.IJsonFactory;
import com.jfinal.json.Json;


public class JsonGsonFactory  implements IJsonFactory {
	private static final JsonGsonFactory me = new JsonGsonFactory();
	
	public static JsonGsonFactory me() {
		return me;
	}

	private static MixedJson mixedJson =  new MixedJson();

	public Json getJson() {
		return mixedJson;
	}

	private static class MixedJson extends Json {

		private static Gson gson;

		public MixedJson() {
			gson = new Gson().newBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
		}
		
		public String toJson(Object object) {
			return gson.toJson(object);
		}

		public <T> T parse(String jsonString, Class<T> type) {
			
			return gson.fromJson(jsonString, type);
		}
	}
}
